// @ts-nocheck
import router from '@system.router';
import fetch from '@system.fetch';//导入fetch模块
import qs from 'querystring'//npm install qs

export default {
    launch() {
        router.push ({
            uri: 'pages/wode/index',
        });
    },
    launch1() {
        router.push ({
            uri: 'pages/zhuce/index',
        });
    },
    data: {
        winfo:"" ,//初始化为空
        username: '',
        password: '',
    },
    // 用户名输入框
    usernameChange(e) {
        this.username = e.value;
    },
    // 密码输入框
    passwordChange(e) {
        this.password = e.value;
    },

    //当按钮按下时触发
    btnclick(){
        //发起网络请求
        fetch.fetch({
            //url:`http://127.0.0.1:8000/person/info/`,//路径
            //url:`http://124.70.5.225:8000/api/login/`,//路径
            data:qs.stringify({'username':this.username,'password':this.password}),
            //验证，转为字符串发给后台
            responseType:"json", //请求的参数类型
            method: "POST",
            success:(resp)=>
            {
                this.winfo = resp.data;  //令获取到的数据赋给winfo
                console.log("返回的数据："+this.winfo)//打印出数据
                if(this.winfo==this.password){
                    router.replace({
                        uri:'pages/shouye/shouye',
                    });
                }
                else{
                    console.log("数据错误，请重新输入数据")
                }
            },
            fail:(resp)=>
            {
                this.winfo = resp.data;
                console.log("获取数据失败："+this.winfo)
            }
        });
    },
}